package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MrCompany;
import com.ruoyi.system.service.IMrCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司Controller
 * 
 * @author ruoyi
 * @date 2022-11-18
 */
@RestController
@RequestMapping("/system/company")
public class MrCompanyController extends BaseController
{
    @Autowired
    private IMrCompanyService mrCompanyService;

    /**
     * 查询公司列表
     */
    @PreAuthorize("@ss.hasPermi('system:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(MrCompany mrCompany)
    {
        startPage();
        List<MrCompany> list = mrCompanyService.selectMrCompanyList(mrCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司列表
     */
    @PreAuthorize("@ss.hasPermi('system:company:export')")
    @Log(title = "公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MrCompany mrCompany)
    {
        List<MrCompany> list = mrCompanyService.selectMrCompanyList(mrCompany);
        ExcelUtil<MrCompany> util = new ExcelUtil<MrCompany>(MrCompany.class);
        util.exportExcel(response, list, "公司数据");
    }

    /**
     * 获取公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:company:query')")
    @GetMapping(value = "/{comId}")
    public AjaxResult getInfo(@PathVariable("comId") Long comId)
    {
        return success(mrCompanyService.selectMrCompanyByComId(comId));
    }

    /**
     * 新增公司
     */
    @PreAuthorize("@ss.hasPermi('system:company:add')")
    @Log(title = "公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MrCompany mrCompany)
    {
        mrCompany.setCreateBy(getUsername());
        return toAjax(mrCompanyService.insertMrCompany(mrCompany));
    }

    /**
     * 修改公司
     */
    @PreAuthorize("@ss.hasPermi('system:company:edit')")
    @Log(title = "公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MrCompany mrCompany)
    {
        return toAjax(mrCompanyService.updateMrCompany(mrCompany));
    }

    /**
     * 删除公司
     */
    @PreAuthorize("@ss.hasPermi('system:company:remove')")
    @Log(title = "公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{comIds}")
    public AjaxResult remove(@PathVariable Long[] comIds)
    {
        //暂时不允许删除公司
        return warn("公司下存在区域、医院、设备信息,不允许删除");

        //return toAjax(mrCompanyService.deleteMrCompanyByComIds(comIds));
    }
}
